package com.carrey.cms_1810.service.impl;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.carrey.cms_1810.dao.UserDao;
import com.carrey.cms_1810.entity.Article;
import com.carrey.cms_1810.entity.User;
import com.carrey.cms_1810.service.UserService;
import com.carrey.cms_1810.utils.MD5Util;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class UserServiceImpl implements UserService{

	@Autowired
	private UserDao userDao;
	
	@Override
	public User getUser(User user) {
		
		return userDao.getUser(user);
	}

	@Override
	public void register(User user) {
		// 对密码进行加密
		user.setPassword(MD5Util.md5(user.getPassword()));
		// 用户角色赋默认值--->0,：普通用户；1：管理员
		user.setRole(0);
		userDao.insertUser(user);
	}

	@Override
	public User getUserByUserNameAndPassword(User user) {
		// 密碼加密處理
		user.setPassword(MD5Util.md5(user.getPassword()));
		return userDao.getUserByUserNameAndPassword(user);
	}

	// 获取用户列表
	@Override
	public PageInfo<User> getUsers(Integer pageNum, Integer pageSize, User user) {
		// 分页封装
		PageHelper.startPage(pageNum, pageSize);
		// 数据查询
		List<User> list = userDao.getUsers(user);
		return new PageInfo<User>(list);
	}

	// 修改用户状态
	@Override
	public boolean updateLocked(User user) {
		return userDao.updateLocked(user);
	}

}
